package leetcode.ArrayAndString;

public class DominantIndex {

    /**
     * 至少是其他数字两倍的最大数
     * @param nums
     * @return 最大元素的索引，否则返回-1
     */
    public static int dominantIndex(int[] nums) {
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > nums[index]) {
                index = i;
            }
        }

        for (int i = 0; i < nums.length; i++) {
            if (i != index && nums[i] * 2 > nums[index]) {
                return -1;
            }
        }
        return index;
    }

    public static void main(String[] args) {
        int[] nums = {0, 0, 0, 1};
        System.out.println(dominantIndex(nums));
    }
}
